﻿<?php

    
    function send_post($url, $post_data) {
      $postdata = http_build_query($post_data);
      $options = array(
        'http' => array(
          'method' => 'POST',
          'header' => 'Content-type:application/x-www-form-urlencoded',
          'content' => $postdata,
          'timeout' => 15 // 超时时间（单位:s）
        )
      );
      $context = stream_context_create($options);
      $result = file_get_contents($url, false, $context);
      return $result;
    }
    if(isset($_GET['sjh']) && $_GET['sjh']){
        $servername = "localhost";
        $username = "anters87";
        $password = "a1023315123";
        $dbname = "anters87";
        $conn = new mysqli($servername, $username, $password, $dbname);
        $conn->query("set names utf8");
        $result = $conn->query("SELECT * FROM hg002 WHERE sjh='{$_GET['sjh']}'");
        if($result->num_rows < 1){
            $result = $conn->query("SELECT * FROM hg002 WHERE yhm='{$_GET['sjh']}'");
        }
        if($result && $row = mysqli_fetch_array($result)){
            $sj = time();
            if($sj - $row['yzmsj'] > 3 * 60){
                $yzm = rand(100000,999999);
                if ($conn->query("UPDATE hg002 SET yzm='{$yzm}',yzmsj='{$sj}' WHERE sjh='{$row['sjh']}'")) {
                    ++$row['sidcs'];
                    $content = '002 验证码：'.$yzm.'，3分钟内输入有效。您可能有违规登录，违规次数：'.$row['sidcs'].'，如有疑问请联系管理员。';
                    $content = iconv("utf-8","gbk//IGNORE",$content);  
                    $post_data = array(
                      'apikey' => 'ae3cf70214b0a2a414489463c4e96075',
                      'mobile' => $row['sjh'],
                      'content' => $content
                    );
                    $post_result = send_post('http://api01.monyun.cn:7901/sms/v2/std/single_send', $post_data);
                    if(!strpos($post_result,'ult":0') === false)
                        exit('0');
                    else exit('-1');
                }

            }else{
                exit('0');
            }
            
        }
        
    }
    exit('-1');
?>